<!DOCTYPE html>
<html lang="cn">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            cursor: pointer;
        }

        body {
            width: 100vw;
            height: 100vh;
            display: flex;
            justify-content: space-between;
        }

        ul {
            width: 100%;
            height: 100%;
        }

        ul li {
            margin: 20px;
            font-size: 20px;
            width: 100%;
            background-color: blueviolet;
        }

        div:nth-child(1) {
            border: 1px solid #ccc;
            width: 300px;
            height: 300px;
            padding: 10px;
        }

        .rubbsh {
            width: 200px;
            height: 300px;
            background-color: #ccc;
            text-align: center;
            font-size: 30px;
            line-height: 300px;
        }
    </style>
</head>

<body>
    <div>
        <h1>组一:知识列表</h1>
        <ul class="box1" id="box1Out">
            <li class="demo" draggable="true">1.css</li>
            <li class="demo" draggable="true">2.html</li>
            <li class="demo" draggable="true">3.java</li>
            <li class="demo" draggable="true">4.vue</li>
            <li class="demo" draggable="true">5.js</li>
        </ul>
    </div>
    <div class="rubbsh">
        垃圾箱
    </div>
    <div class='title'>sdfdsf</div>

</body>

</html>
<script>
    let demolist = document.querySelectorAll('.demo')
    let dragDom = null;
    for (let i = 0; i < demolist.length; i++) {
        demolist[i].ondragstart = function (e) {
            e.dataTransfer.setData('text', e.target.innerHTML)
            dragDom = this;
        }
        demolist[i].ondragend = function (e) {
            e.dataTransfer.clearData('text')
            rubbsh.style.color = 'black'
        }
    }
    let rubbsh = document.querySelector('.rubbsh')
    rubbsh.ondragenter = function () {
        this.style.color = '#fff'
    }
    rubbsh.ondragover = function (e) {
        e.preventDefault()
    }
    rubbsh.ondrop = function (e) {
        // this.style.color = 'black'
        if (confirm('确定')) {
            dragDom.remove()
            console.log(e.dataTransfer.getData('text'));
        }

    }
</script>